#include "AutoLock.h"
#include <windows.h>
#include <assert.h>
#include <boost/lexical_cast.hpp>

ProcessLock::ProcessLock(string key) {
	event = CreateEventA(0, FALSE, TRUE, key.c_str());
	assert(event);
	WaitForSingleObject(event, INFINITE);

}

ProcessLock::~ProcessLock(void) {
	SetEvent(event);
	CloseHandle(event);
}

string GetProcessIDStr() {
	DWORD id = GetCurrentProcessId();
	return boost::lexical_cast<string>(id);
}

ThreadLock::ThreadLock(string key) :
		ProcessLock(GetProcessIDStr() + key) {
}
